package sdufe.lele.exception;

import javax.servlet.http.HttpServletResponse;

/**
 * Created by olivia on 3/22/2017.
 */


/**
 * 异常处理基类
 */
public class ApiException extends RuntimeException {

    //返回的错误信息
    private String message;
    //返回的状态码
    private int httpStatus;

    private String printStackTrace;

    public ApiException(int httpStatus, String message,String printStackTrace) {
        this.message = message;
        this.httpStatus = httpStatus;
        this.printStackTrace = printStackTrace;
    }


    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getHttpStatus() {
        return httpStatus;
    }

    public void setHttpStatus(int httpStatus) {
        this.httpStatus = httpStatus;
    }

    public static ApiException unauthorized(String message) {
        return new ApiException(HttpServletResponse.SC_NOT_FOUND, message,"");//404
    }

    public String getPrintStackTrace() {
        return printStackTrace;
    }

    public void setPrintStackTrace(String printStackTrace) {
        this.printStackTrace = printStackTrace;
    }
}
